package cn.sangedon.review.analysis.controller;

import cn.sangedon.review.analysis.domain.StasticsQuery;
import cn.sangedon.review.analysis.service.StockStasticsService;
import cn.sangedon.review.analysis.stastics.specific.DailyTradeDataStastics;
import cn.sangedon.review.common.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分析交易数据统计结果
 */
@Api(tags = "交易数据分析统计")
@RestController
@RequestMapping("statistics")
public class StatisticsController {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private StockStasticsService stockStasticsService;

    @Autowired
    private DailyTradeDataStastics dailyTradeDataStastics;

    @ApiOperation("分析最近20天历史数据")
    @GetMapping("history/{days}")
    public Result history(@PathVariable Integer days) {
        dailyTradeDataStastics.refreshStockStastics(days);
        return Result.ok();
    }

    @ApiOperation("执行统计分析")
    @GetMapping("exec")
    public Result exec() {
        dailyTradeDataStastics.stastic();
        return Result.ok();
    }

    @ApiOperation("获取统计分析数据列表")
    @PostMapping("list")
    public Result listOrderByType(@RequestBody StasticsQuery stasticsQuery) {
        return Result.okBuilder().data(stockStasticsService.listOrderByType(stasticsQuery)).build();
    }

    /**
     * @param cycleDays 多少个交易日
     * @return
     */
    @ApiOperation("分析股票某个周期的股票涨跌幅变化趋势")
    @GetMapping("trend")
    public Result trend(Integer cycleDays) {
        return Result.okBuilder().data(stockStasticsService.trend(cycleDays)).build();
    }

    /**
     * 实时缩量红股票推荐
     *
     * @return
     */
    @ApiOperation("实时缩量红股票推荐")
    @GetMapping("suggest/fall/shrink/red/intime")
    public Result suggestFallShrinkRedIntime() {
        return Result.okBuilder().data(stockStasticsService.suggestFallShrinkRedIntime()).build();
    }

    /**
     * 下跌缩量红股票 获取下跌缩量红股票结果
     *
     * @param preTradeDate 下跌缩量红股票策略选择结果的前一个交易日： yyyy-MM-dd
     * @param tradeDate 下跌缩量红股票策略选择结果的交易日：yyyy-MM-dd
     * @return
     */
    @ApiOperation("下跌缩量红股票")
    @GetMapping("fall/shrink/red")
    public Result fallShrinkRed(String preTradeDate, String tradeDate) {
        return Result.okBuilder().data(stockStasticsService.fallShrinkRed(preTradeDate, tradeDate)).build();
    }
}
